﻿using System;
using System.ComponentModel;
using System.Xml.Serialization;

namespace SimpleScheduler.Core.Domain
{
    [XmlRoot("Trigger")]
    [Serializable]
    public class Trigger
    {
        [XmlAttribute("Type")]
        public string Type { get; set; }
        [XmlElement]
        public string Name { get; set; }

        [XmlIgnore]
        public DateTime? StartTime;

        [XmlElement("StartTime")]
        public string XmlStartTime
        {
            get { return StartTime.HasValue ? StartTime.Value.ToString("o") : null; }
            set { StartTime = DateTime.Parse(value); }
        }

        [XmlElement]
        public DateTime? EndTime { get; set; }
        [Browsable(false)]
        public bool EndTimeSpecified { get { return EndTime.HasValue; } }

        [XmlElement]
        public int? RepeatCount { get; set; }
        [Browsable(false)]
        public bool RepeatCountSpecified { get { return RepeatCount.HasValue; } }

        [XmlElement]
        public int? RepeatInterval { get; set; }
        [Browsable(false)]
        public bool RepeatIntervalSpecified { get { return RepeatInterval.HasValue; } }

        // Cron
        public string Second { get; set; }
        public string Minute { get; set; }
        public string Hour { get; set; }
        public string Day { get; set; }
        public string Month { get; set; }
        public string DayOfWeek { get; set; }
        public string Year { get; set; }

        public bool Enabled { get; set; }
    }
}